package grape.wx.service.mp.user.api;

import grape.wx.service.mp.MpProperties;
import grape.wx.service.mp.user.po.MpUser;
import grape.common.service.common.IBaseService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.result.WxMpUser;

/**
 * <p>
 * 公众号微信用户表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2020-07-27
 */
public interface IMpUserService extends IBaseService<MpUser> {

    /**
     * 根据openId和appCode判断是否存在
     * @param openId
     * @param appCode
     * @return
     */
    default boolean existByOpenidAndAppCode(String openId,String appCode) {
        return getByOpenidAndAppCode(openId,appCode) != null;
    }

    /**
     * 根据openId和appCode获取
     * @param openId
     * @param appCode
     * @return
     */
    default MpUser getByOpenidAndAppCode(String openId,String appCode) {
        assertParamNotEmpty(openId,"openId不能为空");
        assertParamNotEmpty(appCode,"appCode不能为空");
        MpUser mpUser = new MpUser();
        mpUser.setAppCode(appCode);
        mpUser.setOpenId(openId);
        return getOne(mpUser);
    }

    /**
     * 添加用户
     * @param wxMpUser
     * @param mpConfig
     * @return
     */
    MpUser insert(WxMpUser wxMpUser, MpProperties.MpConfig mpConfig, MpUser.DictHowFrom dictHowFrom);
    /**
     * 添加用户
     * @param wxMpUser
     * @param mpConfig
     * @param mpUser
     * @return
     */
    MpUser updateById(WxMpUser wxMpUser, MpProperties.MpConfig mpConfig, MpUser mpUser);
}
